package com.ruoyi.system.outto.goods.impl;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyun.oss.common.utils.HttpUtil;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.ImgUntil;
import com.ruoyi.common.utils.ImgUntilYS;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttrTemplateMapper;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.interAttr.domain.InterAttr;
import com.ruoyi.system.interAttr.mapper.InterAttrMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.outto.core.MapSort;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.goods.NEWKANKANAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
public class NEWKANKANAPIImpl implements NEWKANKANAPI {
    @Resource
    private GameAttrTemplateMapper gameAttrTemplateMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private ArtRecMapper artRecMapper;
    @Resource
    InterAttrMapper interAttrMapper;

    public static String hmacSHA256(String data, String secret) {
        try {
            // Create HMAC-SHA256 key from the given secret
            SecretKeySpec secretKeySpec = new SecretKeySpec(secret.getBytes(), "HmacSHA256");

            // Get an instance of Mac object implementing HMAC-SHA256
            Mac mac = Mac.getInstance("HmacSHA256");
            mac.init(secretKeySpec);

            // Calculate the HMAC value
            byte[] hmacBytes = mac.doFinal(data.getBytes());

            // Convert result into a hexadecimal string
            StringBuilder sb = new StringBuilder(hmacBytes.length * 2);
            for (byte b : hmacBytes) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (Exception e) {
            throw new RuntimeException("Failed to calculate HMAC-SHA256", e);
        }
    }

    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner);
        String url = "https://api2.kkzhw.com/mall-portal/openapi/import/product/add";

        String time = String.valueOf(System.currentTimeMillis());
        String cover = time+JSONObject.toJSONString(params);
        String sign = hmacSHA256(cover, salePartner.getOther());
        String response = HttpRequest.post(url)
                .header("X-KK-APIKEY", salePartner.getSaleKey())
                .header("X-KK-TIME", time)
                .header("X-KK-SIGNATURE", sign)
                .body(JSONObject.toJSONString(params))
                .execute().body();
        log.info("看看新增请求参数={}", JSONObject.toJSONString(params));
        log.info("看看新增返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        String info = resultJson.getString("info");

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            String data = resultJson.getString("data");
            String id = JSONObject.parseObject(data).getString("productSn");
            result.put("outId", id);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", info);
        return AjaxResult.success(result);
    }


    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, salePartner);
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        ArtRec artRec = artRecs.get(0);
        params.put("productSn", artRec.getOutid());
        String url = "https://api2.kkzhw.com/mall-portal/openapi/import/product/add";

        String time = String.valueOf(System.currentTimeMillis());
        String cover = time+JSONObject.toJSONString(params);
        String sign = hmacSHA256(cover, salePartner.getOther());
        String response = HttpRequest.post(url)
                .header("X-KK-APIKEY", salePartner.getSaleKey())
                .header("X-KK-TIME", time)
                .header("X-KK-SIGNATURE", sign)
                .body(JSONObject.toJSONString(params))
                .execute().body();
        log.info("看看编辑请求参数={}", JSONObject.toJSONString(params));
        log.info("看看编辑返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        String info = resultJson.getString("info");

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", info);
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        Map<String, Object> params = new TreeMap<>();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        ArtRec artRec = artRecs.get(0);
        params.put("productSn",artRec.getOutid());
        String time = String.valueOf(System.currentTimeMillis());
        String cover = time+JSONObject.toJSONString(params);
        String sign = hmacSHA256(cover, salePartner.getOther());
        String response = HttpRequest.post("https://api2.kkzhw.com/mall-portal/openapi/import/product/delete")
                .header("X-KK-APIKEY", salePartner.getSaleKey())
                .header("X-KK-TIME", time)
                .header("X-KK-SIGNATURE", sign)
                .body(JSONObject.toJSONString(params))
                .execute().body();
        log.info("看看删除返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        String info = resultJson.getString("info");

        Map<String, Object> result = new HashMap<>();
        if (!"200".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }
        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", info);
        return AjaxResult.success(result);
    }

    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {

        Map<String,Object> params = new TreeMap<>();
        //自动匹配属性
        String substring = salePartner.getSaleName().substring(salePartner.getSaleName().indexOf("_")+1);
        InterAttr interAttr = interAttrMapper.selectInterAttrByConfig(substring, goodsInfoAndAttrValueDto.getGameId());
        params.put("categoryId", interAttr.getInterGameId());
        params.put("categoryName", interAttr.getInterGameName());
        params.put("pic", goodsInfoAndAttrValueDto.getTitleImg());
        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);
        String imgUrls = infoImgs.stream().map(info -> info.getImgUrl()).collect(Collectors.toList()).stream().collect(Collectors.joining(","));
        params.put("albumPics", imgUrls);
        params.put("price", goodsInfoAndAttrValueDto.getPrice());
        params.put("originalPrice", goodsInfoAndAttrValueDto.getPrice());
        //开始匹配区服属性
        builderServer(goodsInfoAndAttrValueDto, params, interAttr.getServer());
        params.put("gameGoodsYijia", 1);
        params.put("gameGoodsYishou", 1);
        params.put("gameCareinfoPhone", salePartner.getTwoOther());
        params.put("userPhone", salePartner.getTwoOther());
        params.put("description", goodsInfoAndAttrValueDto.getDes().replace("+",""));
        JSONArray extGameAttributeArrays = new JSONArray();
        //开始匹配单选属性
        builderRadioAttr(goodsInfoAndAttrValueDto, extGameAttributeArrays, interAttr.getRadioAttr());
        //开始匹配多选属性
        builderCheckAttr(goodsInfoAndAttrValueDto, extGameAttributeArrays, interAttr.getCheckAttr());
        //开始匹配输入框属性
        builderInputAttr(goodsInfoAndAttrValueDto, extGameAttributeArrays, interAttr.getInputAttr());
        if(extGameAttributeArrays.size()>0) {
            params.put("extGameAttributeArrays", extGameAttributeArrays);
        }else {
            params.put("extGameAttributeArrays", "[]");
        }
        return params;
    }
    private void builderInputAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, JSONArray extGameAttributeArrays, String inputAttr) {
//        JSONArray propertys = Objects.isNull(params.get("property")) ? new JSONArray() : JSONArray.parseArray(params.get("property").toString());
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();

        //========================开始匹配输入框=====================//
        JSONObject jsonObject1 = JSONObject.parseObject(inputAttr);
        String inputJson = jsonObject1.getString("inputJson");
        List<JSONObject> jsonObjects1 = JSONObject.parseArray(inputJson, JSONObject.class);
        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        ArrayList types = new ArrayList<>();
        types.add("number");
        types.add("input");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> inputTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
        List<JSONObject> defInputObjects = new ArrayList<>();
        defInputObjects.addAll(jsonObjects1);
        for (JSONObject object : jsonObjects1) {
            for (GameAttrTemplate inputTemplate : inputTemplates) {
                JSONObject att = new JSONObject();
                String aavName = inputTemplate.getAavName();
                if (Objects.equals(object.getString("aavName"), inputTemplate.getAavName())) {
                    defInputObjects.remove(object);
                    String interId = object.getString("interId");
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (Objects.equals(aavName, name)) {
                            declaredField.setAccessible(true);
                            Object o = null;
                            try {
                                o = declaredField.get(goodsInfoAndAttrValueDto);
                            } catch (IllegalAccessException e) {
                                throw new GlobalException("3属性参数错误，请匹配后重新配置");
                            }
                            if(Objects.nonNull(o)) {
                                String oneValue = String.valueOf(o);
                                if (StringUtils.isNotEmpty(oneValue)) {
                                    att.put("name",interId);
                                    att.put("value",oneValue);
                                    extGameAttributeArrays.add(att);
                                }
                            }
                        }
                    }
                }
            }
        }
        //开始匹配默认值
        for (JSONObject object : defInputObjects) {
            JSONObject att = new JSONObject();
            String defaultValue = object.getString("defaultValue");
            if (StringUtils.isNotEmpty(defaultValue)) {
//                mateMap.put("id", InterConfigId);
//                mateMap.put("val", defaultValue);
                att.put("name",defaultValue);
                att.put("value","1");
                extGameAttributeArrays.add(att);
            }
        }
    }

    /**
     * 开始匹配多选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param checkAttr
     */
    private void builderCheckAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, JSONArray extGameAttributeArrays, String checkAttr) {
        /**
         * 1、先查询自定义中所有多选的字段
         * 2、再查该账号单选字段中的选项
         * 3、再去接口属性匹配表过滤
         */
        Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();
        JSONObject checkAttrJson = JSONObject.parseObject(checkAttr);
        String interCheckBoxReqs = checkAttrJson.getString("interCheckBoxReqs");
        List<JSONObject> checkJsonList = JSONObject.parseArray(interCheckBoxReqs, JSONObject.class);
        if (org.springframework.util.CollectionUtils.isEmpty(checkAttrJson)) {
            throw new GlobalException("接口多选属性暂未配置");
        }

        GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
        gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
        gameAttrTemplate.setIsEnable("0");
        List<String> types = new ArrayList<>();
        types.add("checkbox");
        types.add("boxradio");
        gameAttrTemplate.setFieldTypes(types);
        List<GameAttrTemplate> checkAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);

        for (JSONObject object : checkJsonList) {
            Map<String, Object> confs = new HashMap<>();
            List<String> list = new ArrayList<>();
            for (GameAttrTemplate attrTemplate : checkAttrTemplates) {
                String aavName = attrTemplate.getAavName();
                for (Field declaredField : declaredFields) {
                    String name = declaredField.getName();
                    if (aavName.equals(name)) {
                        declaredField.setAccessible(true);

                        String ydConfigIdLeveOne = object.getString("YdConfigId");
                        if (StringUtils.isNotEmpty(ydConfigIdLeveOne)) {

                            String[] split2 = ydConfigIdLeveOne.split(",");
                            List<String> list2 = new ArrayList<>();
                            for (String s : split2) {
                                s = s.replace(" ", "");
                                list2.add(s);
                            }
                            if (list2.contains(attrTemplate.getId() + "")) {
                                Object o = null;
                                try {
                                    o = declaredField.get(goodsInfoAndAttrValueDto);
                                } catch (IllegalAccessException e) {
                                    throw new GlobalException("多选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                                String oneValue = String.valueOf(o);
                                //一级属性
                                String ydConfigId = object.getString("YdConfigId");
                                if (StringUtils.isNotEmpty(ydConfigId)) {
                                    String[] split = ydConfigId.replace(" ","").split(",");
                                    //一级属性已经匹配，开始匹配二级属性
                                    if (Arrays.asList(split).contains(attrTemplate.getId() + "")) {
                                        String interCheckBoxReqsStr = object.getString("interCheckBoxReqs");
//                                        String interCheckBoxReqsStr = object.getString("interServerRes");
                                        //开始匹配二级属性
                                        List<JSONObject> jsonObjects2 = JSONObject.parseArray(interCheckBoxReqsStr, JSONObject.class);
                                        /**
                                         * 咱们的f字段  多选项都是用空格 隔开，用,号切割数组，跟匹配的数据匹配、匹配上说明此账号勾选的有此属性
                                         */
//                                        List<String> list = new ArrayList<>();
                                        for (JSONObject jsonObject1 : jsonObjects2) {
                                            if (StringUtils.isNotEmpty(oneValue)) {
                                                String[] split1 = oneValue.split(",");
                                                String ydConfigId1 = jsonObject1.getString("YdConfigId");
                                                for (String s : split1) {
                                                    if (Objects.equals(s, ydConfigId1)) {
                                                        String InterConfigId2 = jsonObject1.getString("InterConfigId");
                                                        list.add(InterConfigId2);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                } else {
                                    throw new GlobalException("属性参数错误，请匹配后重新配置");
                                }
                            }
                        }
                    }
                }
            }
            if(CollectionUtils.isNotEmpty(list)){
                confs.put("name",object.getString("name"));
                confs.put("value",StringUtils.join(list,","));
                extGameAttributeArrays.add(confs);
            }
        }
    }

    /**
     * 开始匹配单选属性
     *
     * @param goodsInfoAndAttrValueDto
     * @param radioAttr
     */
    private void builderRadioAttr(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto,JSONArray extGameAttributeArrays, String radioAttr) {
        //========================开始匹配单选属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(radioAttr);
        String interRadioReqs = jsonObject.getString("interRadioReqs");
        log.info(JSONObject.toJSONString(interRadioReqs));
        List<JSONObject> jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
        if (!org.springframework.util.CollectionUtils.isEmpty(jsonObjects)) {
            /**
             * 1、先查询自定义中所有单选的字段
             * 2、再查该账号单选字段中的选项
             * 3、再去接口属性匹配表过滤
             */
            GameAttrTemplate gameAttrTemplate = new GameAttrTemplate();
            gameAttrTemplate.setGameId(goodsInfoAndAttrValueDto.getGameId());
            gameAttrTemplate.setIsEnable("0");
            gameAttrTemplate.setFieldType("radio");
            List<GameAttrTemplate> gameAttrTemplates = gameAttrTemplateMapper.selectGameAttrTemplateList(gameAttrTemplate);
            Field[] declaredFields = goodsInfoAndAttrValueDto.getClass().getDeclaredFields();


            List<JSONObject> defObjects = new ArrayList<>();
            defObjects.addAll(jsonObjects);
            for (JSONObject object : jsonObjects) {
                for (GameAttrTemplate attrTemplate : gameAttrTemplates) {
                    JSONObject att = new JSONObject();
                    String aavName = attrTemplate.getAavName();
                    for (Field declaredField : declaredFields) {
                        String name = declaredField.getName();
                        if (aavName.equals(name)) {
                            //一级属性
                            //注意 YdConfigId 对应的是 f字段对应的 id
                            if (Objects.equals(object.getLong("YdConfigId"), attrTemplate.getId())) {
                                String InterConfigId = object.getString("InterConfigId");
                                defObjects.remove(object);//如果匹配上，则去掉
                                String interRadioReqs1 = object.getString("interRadioReqs");
                                List<JSONObject> jsonObjects2 = JSONObject.parseArray(interRadioReqs1, JSONObject.class);
                                declaredField.setAccessible(true);
                                try {
                                    //获取选择的值 例如  实名中的可二次
                                    Object o = declaredField.get(goodsInfoAndAttrValueDto);
                                    String oneValue = String.valueOf(o);
                                    List<JSONObject> twoAttr = jsonObjects2.stream().filter(j -> Objects.equals(j.getString("YdConfigId"), oneValue)).collect(Collectors.toList());
                                    String interConfigName = object.getString("InterConfigName");
                                    String defaultValue = object.getString("defaultValue");
                                    if (org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        if (StringUtils.isNotEmpty(defaultValue)) {
//                                        mateMap.put("id", InterConfigId);
//                                        mateMap.put("val", defaultValue);
                                            att.put(InterConfigId, defaultValue);
                                            extGameAttributeArrays.add(att);
                                        }
                                    }
//                                if (org.springframework.util.CollectionUtils.isEmpty(twoAttr) && StringUtils.isEmpty(defaultValue)) {
//                                    throw new GlobalException("属性" + interConfigName + " 接口要求必传，但是暂未匹配到，请设置默认值");
//                                }
                                    if (!org.springframework.util.CollectionUtils.isEmpty(twoAttr)) {
                                        JSONObject jsonObject2 = twoAttr.get(0);
                                        String interConfigId2 = jsonObject2.getString("InterConfigId");
                                        att.put("name",InterConfigId);
                                        att.put("value",interConfigId2);
                                        extGameAttributeArrays.add(att);
                                    }
                                } catch (Exception e) {
                                    throw new GlobalException("单选项" + attrTemplate.getFieldName() + "匹配错误");
                                }
                            }
                        }
                    }
                }
            }
            //开始匹配默认值
            for (JSONObject object : defObjects) {
                JSONObject att = new JSONObject();
                String name = object.getString("name");
                interRadioReqs = object.getString("interRadioReqs");
                jsonObjects = JSONObject.parseArray(interRadioReqs, JSONObject.class);
                for (JSONObject objects : jsonObjects) {
                    if(StringUtils.isNotEmpty(objects.getString("defaultValue"))){
                        att.put("name",name);
                        att.put("value",objects.getString("defaultValue"));
                        extGameAttributeArrays.add(att);
                    }
                }
            }
        }
    }

    private void builderServer(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, Map params, String server) {
        //========================开始匹配区服属性=====================//
        JSONObject jsonObject = JSONObject.parseObject(server);
        //开始匹配一级区服
        String interServeReqs = jsonObject.getString("interServeReqs");
        String qufuid = "";
        List<JSONObject> oneServer = JSONObject.parseArray(interServeReqs, JSONObject.class);
        if (Objects.equals(goodsInfoAndAttrValueDto.getGameType(), "0")) {
            qufuid = goodsInfoAndAttrValueDto.getSystemId() + "" + goodsInfoAndAttrValueDto.getCarrierId() + "";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (qufuid.contains(ydServeId)) {
                        params.put("gameAccountQufu", object.getString("name"));
                        break;
                    }
                }
            }
        } else {
            qufuid = goodsInfoAndAttrValueDto.getGroupId()+"";
            for (JSONObject object : oneServer) {
                String ydServeId = object.getString("YdServeId");
                if (StringUtils.isNotEmpty(ydServeId)) {
                    ydServeId = ydServeId.replace(",", "").replace(" ", "");
                    if (ydServeId.contains(qufuid)) {
                        String interServerRes = object.getString("interServerRes");
                        oneServer = JSONObject.parseArray(interServerRes, JSONObject.class);
                        qufuid = goodsInfoAndAttrValueDto.getServerId()+"";
                        for(JSONObject objects : oneServer){
                            String ydServeIds = objects.getString("YdServeId");
                            if (StringUtils.isNotEmpty(ydServeIds)) {
                                ydServeIds = ydServeIds.replace(",", "").replace(" ", "");
                                if (Objects.equals(qufuid, ydServeIds)) {
                                    params.put("gameAccountQufu", object.getString("name")+"|"+objects.getString("name"));
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        Map<String, Object> params = new TreeMap<>();
        params.put("flag_id","23");
        Map<String, Object> header = new TreeMap<>();
        String nonce = RandomStringUtils.randomAlphanumeric(8);
        long timestamp1 = System.currentTimeMillis()/1000;
        String timestamp = String.valueOf(timestamp1);
        header.put("appid","hs230952850019043");
        header.put("timestamp",timestamp);
        header.put("nonce",nonce);
        log.info("看看新增请求参数={}", JSONObject.toJSONString(params));
        String cover = "appid="+"hs230952850019043"+"&nonce="+nonce+"&timestamp="+timestamp+"&secret_key="+"rlsya0r727vx566np2kkqiegow3lp5e9vvvzetsekcn";
        String encode = HttpUtil.urlEncode(cover, "utf-8");
        String sign = DigestUtils.md5Hex(encode).toUpperCase();
        header.put("sign",sign);
        String response = HttpRequest.post("https://api.kkzhw.com/openapi/account_business/selected_list").header("appid","hs230952850019043").header("timestamp",timestamp).header("nonce",nonce)
                .header("sign",sign).body(JSONObject.toJSONString(params)).execute().body();
        log.info(response);
    }
}
